<template>
	<view class="videos">
		<view class="video" v-for=" v in videos" @click="navigator(v.id,v.source)" :key="v.id">
			<image src="../../static/images/cat.jpg" mode="aspectFit"></image>
			<view class="time">{{v.created_at}}</view>
			<view class="title">{{v.title}}</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageIndex: 1,
				pageTotal: 1,
				isBusies: false,
				videos: []
			}
		},
		onLoad() {
			this.getVideos()
		},
		onReachBottom() {
			this.pageIndex++
			this.getVideos()
		},
		methods: {
			async getVideos() {
				if (this.isBusies)
					return
				this.isBusies = true
				const response = await this.$myRequest({
					url: '/api/Video/GetPageListAsync?pageIndex=' + this.pageIndex
				})
				console.log(response)
				this.videos = [...this.videos, ...response.data.Data]
				this.pageTotal = response.data.TotalPage
				this.isBusies = false
			},
			navigator(id, source) {
				uni.navigateTo({
					url: '/pages/detail/detail?id=' + id + '&source=' + source
				})
			}
		}
	}
</script>

<style lang="scss">
	.videos {
		width: 750rpx;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;

		.video {
			width: 335rpx;
			height: 400rpx;
			padding: 20rpx;
			font-size: 24rpx;
			line-height: 40rpx;

			image {
				width: 90%;
				height: 300rpx;
				margin: 0 auto;
				display: block;
			}

			.title {
				height: 80rpx;
				overflow: hidden;
			}
		}
	}
</style>
